package com.zq.it.cms;

import java.util.List;
import java.util.Properties;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

import com.zq.it.cms.common.util.PropertiesHelper;

@Configuration
public class ContextConfig {
	
	@Autowired
	private PropertiesHelper propertiesHelper;
	@Resource(name = "properties")
	private Properties properties;
	
	@Bean
	@DependsOn("propertiesHelper")
	public ReloadableResourceBundleMessageSource messageSource(){
		ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
		messageSource.setCacheSeconds(Integer.parseInt(properties.getProperty("messageSource.cacheSeconds")));
		List<String> baseNames = propertiesHelper.getList("messageSource.basenames.");
		messageSource.setBasenames(baseNames.toArray(new String[baseNames.size()]));
		messageSource.setFallbackToSystemLocale(false);
		messageSource.setAlwaysUseMessageFormat(false);
		messageSource.setDefaultEncoding("UTF-8");
		return messageSource;
	}
	
}
